package edu.java.homework.hw06;

import edu.java.homework.hw06.products.*;

/**
 * Shows the procedure of preparing of the salads.
 * 
 * @author Tsvetan Vasilev
 * 
 */
public class SaladCook {
    // --- Instance Variables --------------------------------------------------
    private static SaladCook instance = null;

    // --- Constructors --------------------------------------------------------
    private SaladCook() {
    }

    // --- Methods(Singleton) --------------------------------------------------
    public static SaladCook instance() {
	if (instance == null) {
	    instance = new SaladCook();
	}
	return instance;
    }

    // --- Methods(Factory) ----------------------------------------------------
    public Salad prepareDefaultSalad() {
	return new Salad();
    }

    public Salad prepareShepherdSalad() {

	// input components
	// ovcharska salata: domati, krastavici, luk, sladka carevica,
	// pecheni chushki, marinovani gybi, shunka, kashkaval, sirene,
	// svareno iajce, maslini,magdanoz, olio, sol, ocet.
	Vegetable[] vegs = { Vegetable.TOMATO, Vegetable.CUCUMBER,
		Vegetable.ONION, Vegetable.CORNS, Vegetable.BAKED_RED_PEPPER,
		Vegetable.MARINADE_MUSHROOMS, Vegetable.OLIVE,
		Vegetable.PARSLEY };

	MeatProduct[] meatProducts = { MeatProduct.HAM };
	// Fruit[] fruits=null;
	MilkProduct[] milkProducts = { MilkProduct.YELLOW_CHEESE,
		MilkProduct.WHITE_CHEESE };
	EggProduct[] eggProducts = { EggProduct.BOILED_EGG };
	Spice[] spices = { Spice.SUNFLOWER_OIL, Spice.SALT, Spice.VINEGARD };

	// operations with components
	wash();
	System.out.println(vegs[0] + ", " + vegs[1] + ", " + vegs[7]+".");

	boil();
	System.out.println(vegs[3]+".");

	peel();
	System.out.println(vegs[1] + ", " + vegs[2] + ", " + eggProducts[0]+".");

	cut();
	System.out.println(vegs[0] + ", " + vegs[1] + ", " + vegs[2] + ", "
		+ vegs[4] + ", " + vegs[5] + ", " + vegs[7] + ", "
		+ meatProducts[0] + ", " + eggProducts[0]+".");
	
	put();
	System.out.println(spices[0] + ", " + spices[1] + ", " + spices[2] + ".");
	
	grate();
	System.out.println(milkProducts[0]+", "+ milkProducts[1]+".");
	
	put();
	System.out.println(vegs[6]+".");
	
	// calculate the price
	Salad salad= new Salad(vegs, null, meatProducts, milkProducts, eggProducts,
		spices);
	//100 gr domati, 50 gr krastavici, 20 gr luk, 50 gr sladka carevica, 
	//50 gr pecheni chushki, 50 gr marinovani gybi, 50 gr shunka, 50 gr kashkaval,
	//50 gr sirene, 1 svareno iajce, 3 maslinki za ukrasa, 10 gr magdanoz, 
	//10 ml olio, 5 gr sol, 20 ml ocet. 
	int[] productWeights={100,50,20,50,50,50,3,10,50,50,50,1,10,5,20};
	int price=calculateSaladPrice(salad, productWeights);
	salad.setPrice(price);
	System.out.printf("%nThe price of salad is: %d%n", salad.getPrice());
	
	return salad;
    }

   
    public Salad prepareShoppSalad() {

	// input components
	Vegetable[] vegs = {};
	MeatProduct[] meatProducts = {};
	// Fruit[] fruits=null;
	MilkProduct[] milkProducts = {};
	EggProduct[] eggProducts = {};
	Spice[] spices = {};

	// operations with components

	return new Salad(vegs, null, meatProducts, milkProducts, eggProducts,
		spices);
    }
    
    public Salad prepareCabbageSalad() {

	// input components
	Vegetable[] vegs = {};
	MeatProduct[] meatProducts = {};
	// Fruit[] fruits=null;
	MilkProduct[] milkProducts = {};
	EggProduct[] eggProducts = {};
	Spice[] spices = {};

	// operations with components

	return new Salad(vegs, null, meatProducts, milkProducts, eggProducts,
		spices);
    }

    public Salad prepareTunaSalad() {

	// input components
	Vegetable[] vegs = {};
	MeatProduct[] meatProducts = {};
	// Fruit[] fruits=null;
	MilkProduct[] milkProducts = {};
	EggProduct[] eggProducts = {};
	Spice[] spices = {};

	// operations with components

	return new Salad(vegs, null, meatProducts, milkProducts, eggProducts,
		spices);
    }

    public Salad preparePotatoesSalad() {

	// input components
	Vegetable[] vegs = {};
	MeatProduct[] meatProducts = {};
	// Fruit[] fruits=null;
	MilkProduct[] milkProducts = {};
	EggProduct[] eggProducts = {};
	Spice[] spices = {};

	// operations with components

	return new Salad(vegs, null, meatProducts, milkProducts, eggProducts,
		spices);
    }

    public Salad prepareRussianSalad() {

	// input components
	//majoneza, kartofi, morkovi, grah, kiseli krastavichki, shunka, 
	//svareno iajce, sol. 
	Vegetable[] vegs = {Vegetable.BOILED_POTATO, Vegetable.CARROT, 
		Vegetable.PEAS, Vegetable.PICKLED_CUCUMBER};
	MeatProduct[] meatProducts = {MeatProduct.HAM};
	//Fruit[] fruits=null;
	//MilkProduct[] milkProducts = null;
	EggProduct[] eggProducts = {EggProduct.BOILED_EGG, EggProduct.MAYONNAISE};
	Spice[] spices = {Spice.SALT};

	// operations with components
	System.out.println("Prepare the Russian salad. " +
			"After that consume it with 1 bottle of vodka :)");
	
	Salad salad=new Salad(vegs, null, meatProducts, null, eggProducts,
		spices);

	// 50 ml majoneza, 150 gr kartofi, 100 gr morkovi, 100 gr grah, 
	//70 gr kiseli krastavichki, 50 gr shunka, 1 svareno iajce, 5 gr sol.
	int[] productWeights={150,100,100,70,50,1,50,5};
	int price= calculateSaladPrice(salad, productWeights);
	salad.setPrice(price);
	System.out.printf("The price of salad is: %d.%n",salad.getPrice());
	return salad;
    }
    
    // calculation of total price of salad
    
    public int calculateSaladPrice(Salad salad, int[] productWeights){
	int sum=0;
	int iter=0;
	
	if(salad.getVegs()!=null){
	    for (Vegetable veg: salad.getVegs()) {
		//System.out.println(veg.name());
		sum+=veg.getPrice()*productWeights[iter++];
	    }
	}
	if(salad.getFruits()!=null){
	    for (Fruit fruit: salad.getFruits()) {
		//System.out.println(fruit.name());
		sum+=fruit.getPrice()*productWeights[iter++];
	    }
	}
	if(salad.getMeatProducts()!=null){
	    for (MeatProduct meat: salad.getMeatProducts()) {
		//System.out.println(meat.name());
		sum+=meat.getPrice()*productWeights[iter++];
	    }
	}
	if(salad.getMilkProducts()!=null){
	    for(MilkProduct milk: salad.getMilkProducts()){
		//System.out.println(milk.name());
		sum+=milk.getPrice()*productWeights[iter++];
	    }
	}
	if(salad.getEggProducts()!=null){
	    for (EggProduct eggProd: salad.getEggProducts()) {
		//System.out.println(eggProd.name());
		sum+=eggProd.getPrice()*productWeights[iter++];
	    }
	}
	if(salad.getSpices()!=null){
	    for(Spice spice: salad.getSpices()){
		//System.out.println(spice.name());
		sum+=spice.getPrice()*productWeights[iter++];
	    }
	}
	return sum;
    }
    

    // --- Methods -> describe operations in cooking ---------------------------
    private void wash() {
	System.out.print("Wash the ");
    }

    private void peel() { // belq
	System.out.print("Peel the ");
    }

    private void cut() {
	System.out.print("Cut the ");
    }

    private void grind() { // strivam,schukvam
	System.out.print("Grind the ");
    }

    private void strain() { // precejdam
	System.out.print("Strain the ");
    }

    private void boil() {
	System.out.print("Boil the ");
    }

    private void grate() { // nastargvam
	System.out.print("Grate the ");
    }

    private void put() {
	System.out.print("Put the ");
    }
    
    
}
